//
//  IWMeViewController.m
//  示例-ItcastWeibo
//
//  Created by MJ Lee on 14-5-3.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import "IWMeViewController.h"
#import "IWSettingArrowItem.h"
#import "IWSettingGroup.h"
#import "IWSystemSettingViewController.h"
#import "AyProfileHeaderView.h"
#import "UIImageExtend.h"
#import "AyDefine.h"
#import "AyAccountTool.h"

@interface IWMeViewController ()
@property (nonatomic, weak)  AyProfileHeaderView * header;
@property (nonatomic, strong)  UIImageView * bgView;
@end

@implementation IWMeViewController

- (void)viewDidLoad
{
//    if (iOS7) {
//        self.tableView.contentInset = UIEdgeInsetsZero;
//    }
    
    [super viewDidLoad];
    
//   self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"设置" style:UIBarButtonItemStyleBordered target:self action:@selector(setting)];
    
    
    [self setupGroup0];
    [self setupGroup1];
    [self setupGroup2];
    [self setupGroup3];
    

    _header = [AyProfileHeaderView header];
    
    AyUserInfoParam *param=[AyUserInfoParam param];
    param.uid = @([AyAccountTool account].uid);
    _header.param =param;
    
    self.tableView.tableHeaderView = _header;
 
    _bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile_cover_background.jpg"]];
    CGFloat bgW = self.view.frame.size.width;
    _bgView.bounds = CGRectMake(0, 0, bgW, bgW);
    _bgView.layer.position = CGPointMake(bgW * 0.5, - bgW / 4);
    _bgView.layer.anchorPoint = CGPointMake(0.5, 0);
 
    [self.tableView insertSubview:_bgView belowSubview:_header];
    
}

- (void)viewDidAppear:(BOOL)animated {}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = NO;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y;
    if (offsetY > 0) return;
    
    // 1.向上的阻力系数（值越大，阻力越大，向上的力越大）
    CGFloat upFactor = 0.6;
    
    // 2.到什么位置开始放大
    CGFloat upMin = - (_bgView.frame.size.height / 6) / (1 - upFactor);
    
    // 3.还没到特定位置，就网上挪动
    if (offsetY >= upMin) {
        _bgView.transform = CGAffineTransformMakeTranslation(0, offsetY * upFactor);
    } else {
        CGAffineTransform transform = CGAffineTransformMakeTranslation(0, offsetY - upMin * (1 - upFactor));
        CGFloat s = 1 + (upMin - offsetY) * 0.005;
        _bgView.transform = CGAffineTransformScale(transform, s, s);
    }
}

///**
// *  设置
// */
//- (void)setting
//{
//    IWSystemSettingViewController *sys = [[IWSystemSettingViewController alloc] init];
//    [self.navigationController pushViewController:sys animated:YES];
//}


- (void)setupGroup0
{
    
    IWSettingGroup *group = [self addGroup];
    
     IWSettingArrowItem *setting = [IWSettingArrowItem itemWithIcon:@"new_friend" title:@"设置" destVcClass:[IWSystemSettingViewController class]];
    
    IWSettingArrowItem *newFriend = [IWSettingArrowItem itemWithIcon:@"new_friend" title:@"新的好友" destVcClass:nil];
    newFriend.badgeValue = @"4";
    group.items = @[setting,newFriend];
}

- (void)setupGroup1
{
    IWSettingGroup *group = [self addGroup];
    
    IWSettingArrowItem *album = [IWSettingArrowItem itemWithIcon:@"album" title:@"我的相册" destVcClass:nil];
    album.subtitle = @"(109)";
    IWSettingArrowItem *collect = [IWSettingArrowItem itemWithIcon:@"collect" title:@"我的收藏" destVcClass:nil];
    collect.subtitle = @"(0)";
    IWSettingArrowItem *like = [IWSettingArrowItem itemWithIcon:@"like" title:@"赞" destVcClass:nil];
    like.badgeValue = @"1";
    like.subtitle = @"(35)";
    group.items = @[album, collect, like];
}

- (void)setupGroup2
{
    IWSettingGroup *group = [self addGroup];
    
    IWSettingArrowItem *pay = [IWSettingArrowItem itemWithIcon:@"pay" title:@"微博支付" destVcClass:nil];
    IWSettingArrowItem *vip = [IWSettingArrowItem itemWithIcon:@"vip" title:@"会员中心" destVcClass:nil];
    group.items = @[pay, vip];
}

- (void)setupGroup3
{
    IWSettingGroup *group = [self addGroup];
    
    IWSettingArrowItem *card = [IWSettingArrowItem itemWithIcon:@"card" title:@"我的名片" destVcClass:nil];
    IWSettingArrowItem *draft = [IWSettingArrowItem itemWithIcon:@"draft" title:@"草稿箱" destVcClass:nil];
    group.items = @[card, draft];
}

@end